home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SUPERPD.PAK / PADVIEW.CPP < prev    next >
C/C++ Source or Header  |  1997-05-06  |  18KB  |  651 lines

  1. // padview.cpp : implementation of the CPadView class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "superpad.h"
  15. #include "padview.h"
  16. #include "paditem.h"
  17. #include "linkitem.h"
  18. #include "tabstop.h"
  19. #include <afxpriv.h>
  20. #include <stdlib.h>
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CPadView
  29.  
  30. IMPLEMENT_DYNCREATE(CPadView, CEditView)
  31.  
  32. BEGIN_MESSAGE_MAP(CPadView, CEditView)
  33.     //{{AFX_MSG_MAP(CPadView)
  34.     ON_WM_CREATE()    
  35.     ON_COMMAND(ID_CHOOSE_FONT, OnChooseFont)
  36.     ON_COMMAND(ID_WORD_WRAP, OnWordWrap)
  37.     ON_UPDATE_COMMAND_UI(ID_WORD_WRAP, OnUpdateWordWrap)
  38.     ON_WM_RBUTTONDOWN()
  39.     ON_COMMAND(ID_CHOOSE_PRINT_FONT, OnChoosePrintFont)
  40.     ON_COMMAND(ID_MIRROR_DISPLAY_FONT, OnMirrorDisplayFont)
  41.     ON_UPDATE_COMMAND_UI(ID_MIRROR_DISPLAY_FONT, OnUpdateMirrorDisplayFont)
  42.     ON_UPDATE_COMMAND_UI(ID_CHOOSE_PRINT_FONT, OnUpdateChoosePrintFont)
  43.     ON_WM_SIZE()
  44.     ON_CONTROL_REFLECT(EN_CHANGE, OnEditChange)
  45.     ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  46.     ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  47.     ON_WM_TIMER()
  48.     //}}AFX_MSG_MAP
  49.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  50.  
  51.     #ifndef _MAC
  52.         ON_COMMAND(ID_SET_TABSTOPS, OnSetTabStops)
  53.     #endif
  54.  
  55. END_MESSAGE_MAP()
  56.  
  57. UINT CPadView::m_nDefTabStops;
  58. UINT CPadView::m_nDefTabStopsOld;
  59. BOOL CPadView::m_bDefWordWrap;
  60. BOOL CPadView::m_bDefWordWrapOld;
  61. LOGFONT NEAR CPadView::m_lfDefFont;
  62. LOGFONT NEAR CPadView::m_lfDefFontOld;
  63. LOGFONT NEAR CPadView::m_lfDefPrintFont;
  64. LOGFONT NEAR CPadView::m_lfDefPrintFontOld;
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // Static initialization/termination
  68.  
  69. static TCHAR BASED_CODE szSettings[] = _T("Settings");
  70. static TCHAR BASED_CODE szTabStops[] = _T("TabStops");
  71. static TCHAR BASED_CODE szFont[] = _T("Font");
  72. static TCHAR BASED_CODE szPrintFont[] = _T("PrintFont");
  73. static TCHAR BASED_CODE szHeight[] = _T("Height");
  74. static TCHAR BASED_CODE szWeight[] = _T("Weight");
  75. static TCHAR BASED_CODE szItalic[] = _T("Italic");
  76. static TCHAR BASED_CODE szUnderline[] = _T("Underline");
  77. static TCHAR BASED_CODE szPitchAndFamily[] = _T("PitchAndFamily");
  78. static TCHAR BASED_CODE szCharSet[] = _T("CharSet");
  79. static TCHAR BASED_CODE szFaceName[] = _T("FaceName");
  80. static TCHAR BASED_CODE szSystem[] = _T("System");
  81. static TCHAR BASED_CODE szWordWrap[] = _T("WordWrap");
  82.  
  83. static void GetProfileFont(LPCTSTR szSec, LOGFONT* plf)
  84. {
  85.     CWinApp* pApp = AfxGetApp();
  86.     plf->lfHeight = pApp->GetProfileInt(szSec, szHeight, 0);
  87.     if (plf->lfHeight != 0)
  88.     {
  89.         plf->lfWeight = pApp->GetProfileInt(szSec, szWeight, 0);
  90.         plf->lfItalic = (BYTE)pApp->GetProfileInt(szSec, szItalic, 0);
  91.         plf->lfUnderline = (BYTE)pApp->GetProfileInt(szSec, szUnderline, 0);
  92.         plf->lfPitchAndFamily = (BYTE)pApp->GetProfileInt(szSec, szPitchAndFamily, 0);
  93.         plf->lfCharSet = (BYTE)pApp->GetProfileInt(szSec, szCharSet, DEFAULT_CHARSET);
  94.         CString strFont = pApp->GetProfileString(szSec, szFaceName, szSystem);
  95.         lstrcpyn((TCHAR*)plf->lfFaceName, strFont, sizeof plf->lfFaceName);
  96.         plf->lfFaceName[sizeof plf->lfFaceName-1] = 0;
  97.     }
  98. }
  99.  
  100. static void WriteProfileFont(LPCTSTR szSec, const LOGFONT* plf, LOGFONT* plfOld)
  101. {
  102.     CWinApp* pApp = AfxGetApp();
  103.  
  104.     if (plf->lfHeight != plfOld->lfHeight)
  105.         pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
  106.     if (plf->lfHeight != 0)
  107.     {
  108.         if (plf->lfHeight != plfOld->lfHeight)
  109.             pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
  110.         if (plf->lfWeight != plfOld->lfWeight)
  111.             pApp->WriteProfileInt(szSec, szWeight, plf->lfWeight);
  112.         if (plf->lfItalic != plfOld->lfItalic)
  113.             pApp->WriteProfileInt(szSec, szItalic, plf->lfItalic);
  114.         if (plf->lfUnderline != plfOld->lfUnderline)
  115.             pApp->WriteProfileInt(szSec, szUnderline, plf->lfUnderline);
  116.         if (plf->lfPitchAndFamily != plfOld->lfPitchAndFamily)
  117.             pApp->WriteProfileInt(szSec, szPitchAndFamily, plf->lfPitchAndFamily);
  118.         if (plf->lfCharSet != plfOld->lfCharSet)
  119.             pApp->WriteProfileInt(szSec, szCharSet, plf->lfCharSet);
  120.         if (_tcscmp(plf->lfFaceName, plfOld->lfFaceName) != 0)
  121.             pApp->WriteProfileString(szSec, szFaceName, (LPCTSTR)plf->lfFaceName);
  122.     }
  123.     *plfOld = *plf;
  124. }
  125.  
  126. void CPadView::Initialize()
  127. {
  128.     CWinApp* pApp = AfxGetApp();
  129.     m_bDefWordWrap = pApp->GetProfileInt(szSettings, szWordWrap, 0);
  130.     m_bDefWordWrapOld = m_bDefWordWrap;
  131.     m_nDefTabStops = pApp->GetProfileInt(szSettings, szTabStops, 8*4);
  132.     m_nDefTabStopsOld = m_nDefTabStops;
  133.     GetProfileFont(szFont, &m_lfDefFont);
  134.     m_lfDefFontOld = m_lfDefFont;
  135.     GetProfileFont(szPrintFont, &m_lfDefPrintFont);
  136.     m_lfDefPrintFontOld = m_lfDefPrintFont;
  137. }
  138.  
  139. void CPadView::Terminate()
  140. {
  141.     CWinApp* pApp = AfxGetApp();
  142.     if (m_nDefTabStops != m_nDefTabStopsOld)
  143.         pApp->WriteProfileInt(szSettings, szTabStops, m_nDefTabStops);
  144.     if (m_bDefWordWrap != m_bDefWordWrapOld)
  145.         pApp->WriteProfileInt(szSettings, szWordWrap, m_bDefWordWrap);
  146.     WriteProfileFont(szFont, &m_lfDefFont, &m_lfDefFontOld);
  147.     WriteProfileFont(szPrintFont, &m_lfDefPrintFont, &m_lfDefPrintFontOld);
  148. }
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CPadView construction/destruction
  152.  
  153. CPadView::CPadView()
  154. {
  155.     #ifndef _MAC
  156.         m_nTabStops = m_nDefTabStops;
  157.     #endif
  158.  
  159.     m_uTimerID = 0;
  160. }
  161.  
  162. BOOL CPadView::PreCreateWindow(CREATESTRUCT& cs)
  163. {
  164.     if (!CEditView::PreCreateWindow(cs))
  165.         return FALSE;
  166.  
  167.     if (m_bDefWordWrap)
  168.         cs.style &= ~(WS_HSCROLL|ES_AUTOHSCROLL);
  169.  
  170.     return TRUE;
  171. }
  172.  
  173. int CPadView::OnCreate(LPCREATESTRUCT lpcs)
  174. {
  175.     if (CEditView::OnCreate(lpcs) != 0)
  176.         return -1;
  177.     if (m_lfDefFont.lfHeight != 0)
  178.     {
  179.         m_font.CreateFontIndirect(&m_lfDefFont);
  180.         SetFont(&m_font);
  181.     }
  182.     if (m_lfDefPrintFont.lfHeight != 0)
  183.     {
  184.         m_fontPrint.CreateFontIndirect(&m_lfDefPrintFont);
  185.         SetPrinterFont(&m_fontPrint);
  186.     }
  187.     return 0;
  188. }
  189.  
  190. /////////////////////////////////////////////////////////////////////////////
  191. // CPadView Word Wrap support
  192.  
  193. BOOL CPadView::IsWordWrap() const
  194. {
  195.     return (GetStyle() & ES_AUTOHSCROLL) == 0;
  196. }
  197.  
  198. BOOL CPadView::SetWordWrap(BOOL bWordWrap)
  199. {
  200.     bWordWrap = !!bWordWrap;    // make sure ==TRUE || ==FALSE
  201.     if (IsWordWrap() == bWordWrap)
  202.         return FALSE;
  203.  
  204.     // preserve original control's state.
  205.     CFont* pFont = GetFont();
  206.     int nLen = GetBufferLength();
  207.     TCHAR* pSaveText = new TCHAR[GetBufferLength()+1];
  208.     GetWindowText(pSaveText, nLen+1);
  209.  
  210.     // create new edit control with appropriate style and size.
  211.     DWORD dwStyle = dwStyleDefault & ~(ES_AUTOHSCROLL|WS_HSCROLL|WS_VISIBLE);
  212.     if (!bWordWrap)
  213.         dwStyle |= ES_AUTOHSCROLL|WS_HSCROLL;
  214.  
  215.     CWnd* pParent = GetParent();
  216.     CRect rect;
  217.     GetWindowRect(rect);
  218.     pParent->ScreenToClient(rect);
  219.     CWnd* pFocus = GetFocus();
  220.  
  221.     UINT nID = GetDlgCtrlID();
  222.  
  223.     HWND hWnd = ::CreateWindowEx(WS_EX_CLIENTEDGE, _T("edit"), NULL, dwStyle,
  224.         rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
  225.         pParent->m_hWnd, (HMENU)nID, AfxGetInstanceHandle(), NULL);
  226.  
  227.     if (hWnd == NULL)
  228.     {
  229.         delete[] pSaveText;
  230.         return FALSE;
  231.     }
  232.  
  233.     // set the window text to nothing to make sure following set doesn't fail
  234.     SetWindowText(NULL);
  235.  
  236.     // restore visual state
  237.     ::SetWindowText(hWnd, pSaveText);
  238.     delete[] pSaveText;
  239.     if (pFont != NULL)
  240.     {
  241.         ASSERT(pFont->m_hObject != NULL);
  242.         ::SendMessage(hWnd, WM_SETFONT, (WPARAM)pFont->m_hObject, 0);
  243.     }
  244.  
  245.     // detach old window, attach new
  246.     SetDlgCtrlID(nID+1);
  247.     HWND hWndOld = Detach();
  248.     ::SetWindowLong(hWndOld, GWL_WNDPROC, (LONG)*GetSuperWndProcAddr());
  249.     ASSERT(m_hWnd == NULL);
  250.     SubclassWindow(hWnd);
  251.     ASSERT(m_hWnd == hWnd);
  252.     GetParentFrame()->SendMessage(WM_RECALCPARENT);
  253.     
  254.     #ifndef _MAC
  255.         UINT nTabStops = m_nTabStops;
  256.         GetEditCtrl().SetTabStops(nTabStops);
  257.     #endif
  258.     
  259.     GetClientRect(&rect);
  260.     SetWindowPos(NULL, 0, 0, 0, 0,
  261.         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
  262.     SetWindowPos(NULL, 0, 0, 0, 0,
  263.         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_DRAWFRAME);
  264.     SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
  265.     UpdateWindow();
  266.  
  267.     // destroy old
  268.     ::SetWindowPos(hWndOld, NULL, 0, 0, 0, 0,
  269.         SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
  270.         SWP_NOZORDER);
  271.     ::DestroyWindow(hWndOld);
  272.  
  273.     // restore rest of state...
  274.     GetEditCtrl().LimitText(nMaxSize);
  275.     if (pFocus == this)
  276.         SetFocus();
  277.  
  278.     // notify container that doc changed
  279.     GetDocument()->UpdateAllItems(NULL);
  280.  
  281.     ASSERT_VALID(this);
  282.     return TRUE;
  283. }
  284.  
  285. /////////////////////////////////////////////////////////////////////////////
  286. // CPadView Printing support
  287.  
  288. void CPadView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  289. {
  290.     CEditView::OnBeginPrinting(pDC, pInfo);
  291.  
  292.     LPCTSTR pszFileName = GetDocument()->GetPathName();
  293.     BOOL bForceSysTime = _tcschr(pszFileName, '.') == NULL;
  294.     CTime timeSys = CTime::GetCurrentTime();
  295.     CFileStatus status;
  296.     CFile::GetStatus(pszFileName, status);
  297.  
  298.     if (dlgPageSetup.m_iHeaderTime != 0 || bForceSysTime)
  299.         m_timeHeader = timeSys;
  300.     else
  301.         m_timeHeader = status.m_mtime;
  302.  
  303.     if (dlgPageSetup.m_iFooterTime != 0 || bForceSysTime)
  304.         m_timeFooter = timeSys;
  305.     else
  306.         m_timeFooter = status.m_mtime;
  307.  
  308.     if (!pInfo->m_bPreview)
  309.         return;
  310.  
  311.     CWaitCursor wait;
  312.     pInfo->m_nCurPage = 0xFFFF;
  313.     OnPrepareDC(pDC, pInfo);
  314.  
  315.     UINT nIndex = LOWORD(GetEditCtrl().GetSel());
  316.     UINT nCurPage = 1;
  317.     while (nCurPage < (UINT)m_aPageStart.GetSize())
  318.     {
  319.         if (nIndex < m_aPageStart[nCurPage])
  320.             break;
  321.         nCurPage++;
  322.     }
  323.     pInfo->m_nCurPage = nCurPage;
  324.     pInfo->SetMaxPage(m_aPageStart.GetSize());
  325.     m_nPreviewPage = nCurPage;
  326. }
  327.  
  328. void CPadView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  329. {
  330.     // get string to show as "filename" in header/footer
  331.     LPCTSTR pszFileName = GetDocument()->GetPathName();
  332.     if (pszFileName[0] == 0)
  333.         pszFileName = GetDocument()->GetTitle();
  334.  
  335.     // go thru global CPageSetupDlg to format the header and footer
  336.     CString strHeader;
  337.     dlgPageSetup.FormatHeader(strHeader, m_timeHeader, pszFileName,
  338.         pInfo->m_nCurPage);
  339.     CString strFooter;
  340.     dlgPageSetup.FormatFooter(strFooter, m_timeFooter, pszFileName,
  341.         pInfo->m_nCurPage);
  342.  
  343.     TEXTMETRIC tm;
  344.     pDC->GetTextMetrics(&tm);
  345.     int cyChar = tm.tmHeight;
  346.     CRect rectPage = pInfo->m_rectDraw;
  347.  
  348.     // draw and exclude space for header
  349.     if (!strHeader.IsEmpty())
  350.     {
  351.         pDC->TextOut(rectPage.left, rectPage.top, strHeader);
  352.         rectPage.top += cyChar + cyChar / 4;
  353.         pDC->MoveTo(rectPage.left, rectPage.top);
  354.         pDC->LineTo(rectPage.right, rectPage.top);
  355.         rectPage.top += cyChar / 4;
  356.     }
  357.  
  358.     // allow space for footer
  359.     pInfo->m_rectDraw = rectPage;
  360.     if (!strFooter.IsEmpty())
  361.         pInfo->m_rectDraw.bottom -= cyChar + cyChar/4 + cyChar/4;
  362.  
  363.     // draw body text
  364.     CEditView::OnPrint(pDC, pInfo);
  365.  
  366.     // draw footer
  367.     if (!strFooter.IsEmpty())
  368.     {
  369.         rectPage.bottom -= cyChar;
  370.         pDC->TextOut(rectPage.left, rectPage.bottom, strFooter);
  371.         rectPage.bottom -= cyChar / 4;
  372.         pDC->MoveTo(rectPage.left, rectPage.bottom);
  373.         pDC->LineTo(rectPage.right, rectPage.bottom);
  374.         rectPage.bottom -= cyChar / 4;
  375.     }
  376. }
  377.  
  378. void CPadView::OnScrollTo(CDC*, CPrintInfo* pInfo, POINT)
  379. {
  380.     UINT nPage = pInfo->m_nCurPage;
  381.     ASSERT(nPage < (UINT)m_aPageStart.GetSize());
  382.     if (nPage != m_nPreviewPage)
  383.     {
  384.         UINT nIndex = m_aPageStart[nPage];
  385.         GetEditCtrl().SetSel((int)nIndex, (int)nIndex);
  386.     }
  387. }
  388.  
  389. /////////////////////////////////////////////////////////////////////////////
  390. // CPadView Font Handling
  391.  
  392. void CPadView::OnChooseFont()
  393. {
  394.    // get current font description
  395.    CFont* pFont = GetFont();
  396.    LOGFONT lf;
  397.    if (pFont != NULL)
  398.        pFont->GetObject(sizeof(LOGFONT), &lf);
  399.    else
  400.        ::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
  401.  
  402.     CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
  403.     if (dlg.DoModal() == IDOK)
  404.     {
  405.         // switch to new font.
  406.         m_font.DeleteObject();
  407.         if (m_font.CreateFontIndirect(&lf))
  408.         {
  409.             CWaitCursor wait;
  410.             SetFont(&m_font);
  411.             m_lfDefFont = lf;
  412.  
  413.             if (GetPrinterFont() == NULL)
  414.             {
  415.                 // notify container that content has changed
  416.                 GetDocument()->UpdateAllItems(NULL);
  417.             }
  418.         }
  419.     }
  420. }
  421.  
  422. static void ScaleLogFont(LPLOGFONT plf, const CDC& dcFrom, const CDC& dcTo)
  423.     // helper to scale log font member from one DC to another!
  424. {
  425.     plf->lfHeight = MulDiv(plf->lfHeight,
  426.         dcTo.GetDeviceCaps(LOGPIXELSY), dcFrom.GetDeviceCaps(LOGPIXELSY));
  427.     plf->lfWidth = MulDiv(plf->lfWidth,
  428.         dcTo.GetDeviceCaps(LOGPIXELSX), dcFrom.GetDeviceCaps(LOGPIXELSX));
  429. }
  430.  
  431. void CPadView::OnChoosePrintFont()
  432. {
  433.     CWaitCursor wait;
  434.     CFont* pFont = GetPrinterFont();
  435.     LOGFONT lf;
  436.     LPLOGFONT plf = NULL;
  437.     if (pFont != NULL)
  438.     {
  439.         pFont->GetObject(sizeof(LOGFONT), &lf);
  440.         plf = &lf;
  441.     }
  442.  
  443.     // magic to get printer dialog that would be used if we were printing!
  444.     CPrintDialog dlgPrint(FALSE);
  445.     if (!AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd))
  446.     {
  447.         AfxMessageBox(IDP_ERR_GET_DEVICE_DEFAULTS);
  448.         return;
  449.     }
  450.     wait.Restore();
  451.     HDC hdcPrint = dlgPrint.CreatePrinterDC();
  452.     if (hdcPrint == NULL)
  453.     {
  454.         AfxMessageBox(IDP_ERR_GET_PRINTER_DC);
  455.         return;
  456.     }
  457.  
  458.     CDC dcScreen;
  459.     dcScreen.Attach(::GetDC(NULL));
  460.     CDC dcPrint;
  461.     dcPrint.Attach(hdcPrint);
  462.  
  463.     if (plf != NULL)
  464.     {
  465.         // need to map initial logfont to screen metrics.
  466.         ::ScaleLogFont(plf, dcPrint, dcScreen);
  467.     }
  468.  
  469.     // now bring up the dialog since we know the printer DC
  470.     CFontDialog dlg(plf, CF_PRINTERFONTS, &dcPrint);
  471.     if (dlg.DoModal() == IDOK)
  472.     {
  473.         // map the resulting logfont back to printer metrics.
  474.         lf = dlg.m_lf;
  475.         ::ScaleLogFont(&lf, dcScreen, dcPrint);
  476.  
  477.         m_fontPrint.DeleteObject();
  478.         if (m_fontPrint.CreateFontIndirect(&lf))
  479.         {
  480.             SetPrinterFont(&m_fontPrint);
  481.             m_lfDefPrintFont = lf;
  482.  
  483.             // notify container that content has changed
  484.             GetDocument()->UpdateAllItems(NULL);
  485.         }
  486.     }
  487.     //NOTE: destructor will call dcPrint.DeleteDC
  488.  
  489.     ::ReleaseDC(NULL, dcScreen.Detach());
  490. }
  491.  
  492. void CPadView::OnMirrorDisplayFont()
  493. {
  494.     if (GetPrinterFont() != NULL)
  495.     {
  496.         SetPrinterFont(NULL);
  497.         m_lfDefPrintFont.lfHeight = 0;
  498.  
  499.         // notify container that content changed
  500.         GetDocument()->UpdateAllItems(NULL);
  501.     }
  502. }
  503.  
  504. void CPadView::OnUpdateChoosePrintFont(CCmdUI* pCmdUI)
  505. {
  506.     pCmdUI->SetCheck(GetPrinterFont() != NULL);
  507. }
  508.  
  509. void CPadView::OnUpdateMirrorDisplayFont(CCmdUI* pCmdUI)
  510. {
  511.     pCmdUI->SetCheck(GetPrinterFont() == NULL);
  512. }
  513.  
  514. /////////////////////////////////////////////////////////////////////////////
  515. // CPadView Tab Stops
  516.  
  517. #ifndef _MAC // CEditView::SetTabStops is not supported on the MAC
  518. void CPadView::OnSetTabStops()
  519. {
  520.     CSetTabStops dlg;
  521.     dlg.m_nTabStops = m_nTabStops/4;
  522.     if (dlg.DoModal() == IDOK)
  523.     {
  524.         CWaitCursor wait;
  525.         SetTabStops(dlg.m_nTabStops*4);
  526.         m_nDefTabStops = m_nTabStops;
  527.  
  528.         // notify container that content changed
  529.         GetDocument()->UpdateAllItems(NULL);
  530.     }
  531. }
  532. #endif 
  533.  
  534. /////////////////////////////////////////////////////////////////////////////
  535. // CPadView Word Wrap
  536.  
  537. void CPadView::OnUpdateWordWrap(CCmdUI* pCmdUI)
  538. {
  539.     pCmdUI->SetCheck(IsWordWrap());
  540. }
  541.  
  542. void CPadView::OnWordWrap()
  543. {
  544.     CWaitCursor wait;
  545.     SetWordWrap(!IsWordWrap());
  546.     m_bDefWordWrap = IsWordWrap();
  547. }
  548.  
  549. /////////////////////////////////////////////////////////////////////////////
  550. // CPadView commands
  551.  
  552. void CPadView::OnRButtonDown(UINT, CPoint)
  553. {
  554.     GetParentFrame()->BringWindowToTop();
  555. }
  556.  
  557. void CPadView::OnSize(UINT nType, int cx, int cy)
  558. {
  559.     CWaitCursor wait;
  560.     CEditView::OnSize(nType, cx, cy);
  561.  
  562.     CFrameWnd* pFrameWnd = GetParentFrame();
  563.     ASSERT_VALID(pFrameWnd);
  564.  
  565.     if ((pFrameWnd->GetStyle() & WS_VISIBLE) &&
  566.         pFrameWnd->IsKindOf(RUNTIME_CLASS(COleIPFrameWnd)))
  567.     {
  568.         // update the cx part of the extent to the width of the control
  569.         COleServerItem* pItem = GetDocument()->GetEmbeddedItem();
  570.  
  571.         // only update if it has actually changed
  572.         if ((int)pItem->m_sizeExtent.cx != cx)
  573.         {
  574.             pItem->m_sizeExtent.cx = cx;
  575.             OnEditChange();
  576.         }
  577.     }
  578. }
  579.  
  580. /////////////////////////////////////////////////////////////////////////////
  581. // CPadView OLE support
  582.  
  583. void CPadView::OnEditChange()
  584. {
  585.     CEditView::OnEditChange();
  586.  
  587.     if (m_uTimerID != 0) // if outstanding timer kill it
  588.         KillTimer(m_uTimerID);
  589.     m_uTimerID = SetTimer(1, 200, NULL); //set a timer for 200 milliseconds
  590.     if (m_uTimerID == 0) // no timer available so force update now
  591.         GetDocument()->UpdateAllItems(NULL);
  592. }
  593.  
  594. void CPadView::OnEditCopy()
  595. {
  596.     CWaitCursor wait;
  597.  
  598.     // get the current selection
  599.     UINT nFrom, nTo;
  600.     GetEditCtrl().GetSel((int&)nFrom, (int&)nTo);
  601.  
  602.     // what gets copied depends on partial vs. full selection
  603.     if ((nFrom == 0 && nTo == (UINT)GetWindowTextLength()))
  604.     {
  605.         // copy entire document to the clipboard
  606.         GetDocument()->GetEmbeddedItem()->CopyToClipboard(TRUE);
  607.     }
  608.     else
  609.     {
  610.         // copy linked item to clipboard
  611.         CPadLinkItem item(GetDocument(), nFrom, nTo);
  612.         item.CopyToClipboard(TRUE);
  613.     }
  614. }
  615.  
  616. void CPadView::OnEditCut()
  617. {
  618.     OnEditCopy();
  619.     CEditView::OnEditCut();
  620. }
  621.  
  622. void CPadView::OnTimer(UINT nIDEvent)
  623. {
  624.     if (m_uTimerID != nIDEvent) // not our timer
  625.     {
  626.         CEditView::OnTimer(nIDEvent);
  627.         return;
  628.     }
  629.  
  630.     KillTimer(m_uTimerID); // kill one-shot timer
  631.     m_uTimerID = 0;
  632.     GetDocument()->UpdateAllItems(NULL);
  633. }
  634.  
  635. /////////////////////////////////////////////////////////////////////////////
  636. // CPadView diagnostics
  637.  
  638. #ifdef _DEBUG
  639. void CPadView::AssertValid() const
  640. {
  641.     CEditView::AssertValid();
  642. }
  643.  
  644. void CPadView::Dump(CDumpContext& dc) const
  645. {
  646.     CEditView::Dump(dc);
  647. }
  648. #endif //_DEBUG
  649.  
  650. /////////////////////////////////////////////////////////////////////////////
  651.